﻿using System;

namespace Geometry
{
    public class Vector : Point
    {
        #region 字段属性
        private double norm;
        public double Norm { get => norm; }
        #endregion

        #region 构造器
        public Vector(string id, double x, double y)
        {
            this.ID = id;
            this.X = x;
            this.Y = y;
        }
        public Vector(string id, Point pointTo, Point pointFrom)
        {
            ID = id;
            X = pointTo.X - pointFrom.X;
            Y = pointTo.Y - pointFrom.Y;
            SetNorm();
        }
        public Vector(string id, Line line)
        {
            ID = id;
            X = line.PointTo.X - line.PointFrom.X;
            Y = line.PointTo.Y - line.PointFrom.Y;
            SetNorm();
        }
        public Vector() { }
        #endregion

        #region 方法
        /// <summary>
        /// 设置向量模
        /// </summary>
        private void SetNorm()
        {
            try
            {
                double x_2 = Math.Pow(X, 2);
                double y_2 = Math.Pow(Y, 2);
                norm = Math.Sqrt(x_2 + y_2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        /// <summary>
        /// 获取向量叉积
        /// </summary>
        /// <param name="vectorOther">另一个向量</param>
        public double GetCrossProduct(Vector vectorOther)
        {
            double d1 = this.X * vectorOther.Y;
            double d2 = this.Y * vectorOther.X;
            return d1 - d2;
        }
        #endregion
    }
}
